package com.hualan.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.CourseMapper;
import com.hualan.sfzy.mapper.consult.ConsultMapper;
import com.hualan.sfzy.model.entity.Consult;
import com.hualan.sfzy.model.entity.Course;
import com.hualan.sfzy.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    CourseMapper courseMapper;
    @Override
    public int add(Course entity) {
        return courseMapper.insert(entity);
    }

    @Override
    public int edit(Course entity) {
        return courseMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return courseMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return courseMapper.deleteBatch(ids);
    }

    @Override
    public List<Course> find() {
        return courseMapper.select(new Course());
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Course entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> list = courseMapper.select(entity);
        PageInfo<Course> pageInfo = new PageInfo<>(list);
        Map<String, Object>  resultMap = new HashMap<>();

        resultMap.put(CommonConstant.PAGE_LIST, list);    // 当前页数据列表
        resultMap.put(CommonConstant.TOTAL, pageInfo.getTotal());      // 总记录数
        resultMap.put(CommonConstant.PAGE_NUM, pageInfo.getPageNum()); // 当前页码
        resultMap.put(CommonConstant.PAGE_SIZE, pageInfo.getPageSize()); // 每页大小
        resultMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());  // 总页数

        return resultMap;
    }

    @Override
    public Course findById(Integer id) {
        return courseMapper.selectById(id);
    }
    @Autowired
    ConsultMapper consultMapper;

    @Override
    public List<Consult> getAllPsychologist() {
        List<Consult> list = consultMapper.selectAllPsychologist();
        return list;
    }
}
